package senpec.qc.harmony.instrument.equipment;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import senpec.qc.harmony.base.exception.NoResultException;
import senpec.qc.harmony.base.mybatisplus.IBaseServiceImpl;
import senpec.qc.harmony.base.mybatisplus.Result;

import java.util.List;

@Service
@Slf4j
@RequiredArgsConstructor
public class EquipmentServiceImpl extends IBaseServiceImpl<EquipmentMapper, Equipment> implements EquipmentService {
    private final EquipmentMapper equipmentMapper;

    @Override
    public Result<Equipment> getById(Long id) {
        Equipment equipment = equipmentMapper.selectById(id);
        if (equipment == null) {
            throw new NoResultException("未找到该数据");
        } else {
            return Result.ok(equipment);
        }
    }

    @Override
    public Result<List<Equipment>> getListByConditions(Equipment conditions) {
        List<Equipment> equipmentList = equipmentMapper.selectList(null);
        return Result.ok(equipmentList);
    }

    @Override
    public Result<Equipment> insertOne(Equipment entity) {
        equipmentMapper.insert(entity);
        return Result.ok(entity);
    }

}